// import storage from 'store'
import { createI18n, useI18n as use } from "vue-i18n";
import zh_CN from './zh-CN.js';
import en_US from './en-US.js';

const messages = {
	'en': en_US,
	'zh_CN': zh_CN
}
export function getLanguage() {
	// const lang = storage.get('lan') || 'zh_CN';
	const lang = 'zh_CN';
	return lang;
}

// export const langKeys = [
// 	{ value: "zh_CN", label: "简体中文" },
// 	{ value: "en_US", label: "English" },
// ];

/*
//引入同级目录下文件
const modules = import.meta.globEager(
  "./[[:lower:]][[:lower:]]_[[:upper:]][[:upper:]].ts"
);
function getLangAll(): any {
  const message: any = {};
  console.log(modules);
  getLangFiles(modules, message);
  return message;
}
function getLangFiles(mList: any, msg: any) {
  for (const path in mList) {
	if (mList[path].default) {
	  const pathName = path.substr(path.lastIndexOf("/") + 1, 5);
	  if (msg[pathName]) {
		msg[pathName] = {
		  ...mList[pathName],
		  ...mList[path].default,
		};
	  } else {
		msg[pathName] = mList[path].default;
	  }
	}
  }
} 
*/
//注册i8n实例并引入语言文件
const i18n = createI18n({
	legacy: false,
	globalInjection: true, // 全局注册 $t方法
	locale: getLanguage(),
	messages,
});

export const useI18n = use;
export default i18n;

